package com.greenold.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.greenold.common.annotation.Log;
import com.greenold.common.core.controller.BaseController;
import com.greenold.common.core.domain.AjaxResult;
import com.greenold.common.enums.BusinessType;
import com.greenold.service.domain.CarePlan;
import com.greenold.service.service.ICarePlanService;
import com.greenold.common.utils.poi.ExcelUtil;
import com.greenold.common.core.page.TableDataInfo;

/**
 * 护理计划Controller
 *
 * @author YueYang
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/service/plan")
public class CarePlanController extends BaseController {
    @Autowired
    private ICarePlanService carePlanService;

    /**
     * 查询护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('service:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarePlan carePlan) {
        startPage();
        List<CarePlan> list = carePlanService.selectCarePlanList(carePlan);
        return getDataTable(list);
    }

    /**
     * 根据id 获取护理计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(carePlanService.selectCarePlanById(id));
    }

    /**
     * 新增护理计划
     */
    @PreAuthorize("@ss.hasPermi('service:plan:add')")
    @Log(title = "护理计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarePlan carePlan) {
        return toAjax(carePlanService.insertCarePlan(carePlan));
    }

    /**
     * 修改护理计划
     */
    @PreAuthorize("@ss.hasPermi('service:plan:edit')")
    @Log(title = "护理计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarePlan carePlan) {
        return toAjax(carePlanService.updateCarePlan(carePlan));
    }


    /**
     * 删除护理计划
     */
    @PreAuthorize("@ss.hasPermi('service:plan:remove')")
    @Log(title = "护理计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") String id) {
        return toAjax(carePlanService.deleteCarePlanById(id));
    }


    /**
     * 启用禁用护理等级
     */
    @PreAuthorize("@ss.hasPermi('service:level:stop')")
    @Log(title = "护理等级", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam Integer id, @RequestParam String status) {
        return toAjax(carePlanService.changeStatus(id, status));
    }


    /**
     * 查询与护理计划关联的所有护理等级id
     */
    //@PreAuthorize("@ss.hasPermi('service:plan:query')")
    @GetMapping("/ids")
    public AjaxResult getLevelIds() {
        return success(carePlanService.getLevelIds());
    }
}
